import axios from "axios";

export type DataWrapper<T> = {
  Code: number;
  Data: Partial<T>;
  Msg: string
};

const request = axios.create({
  baseURL: '',
});

request.interceptors.response.use(
  // 请求成功
  response => {
    let data = response.data;

    if (!(data instanceof Object)) {
      try {
        data = JSON.parse(data);
      } catch (error) {
        return Promise.reject(error);
      }
    }
    return data.Data;
  },
  // 请求失败
  error => {
    return Promise.reject(error.response);
  },
);

export default request;